﻿@{
    ViewBag.Title = "Index";
}

<style type="text/css">
    body {
        background: #fff !important;
        overflow: auto !important;
    }
    .apply-content {
        width: 100%;
        height: auto;      
        display: flex;
        /*justify-content: space-between;*/
        flex-wrap: wrap;
        background-color: #fff;
        padding-bottom: 30px;
    }
    .apply-box {
        /*margin-top: 60px;*/
        margin-top: 30px;
        width: 220px;
        height: 310px;
        background:rgba(91,165,239,0);
        box-shadow:0px 2px 4px 0px #73B0FB;
        border-radius:5px;
        margin-right: 13px;
    }
        .apply-box img {
            width: 100%;
            height: 116px;
        }
    .apply-text {
        width: 150px;
        height: auto;
        margin: 0 auto;
        /*margin-top: 38px;*/
    }
        .apply-text h5 {
            color: #374057;
            font-size: 18px;
            line-height: 18px;
            font-weight:bold;
            text-align: center;
            margin: 15px 0;
        }
        .apply-text p {
            color: #374057 ;
            font-size: 14px;
            line-height: 16px;
        }
        .apply-text span {
            color: #FF6D01;
            font-size: 18px;
            line-height: 18px;
            width: 100%;
            text-align: center;
            display:inline-block;
            margin-bottom: 24px;
        }
        .apply-text input {
            background-color: #5BA5EF;
            color: #fff;
            font-size: 14px;
            width: 100%;
            height: 32px;
            line-height: 32px;
            border-radius:5px;
            border: none;
        }
     .apply-text .overdue {
            background-color: #FF604B;
            color: #fff;
        }
      .apply-text .management {
            background-color: #fff;
            color:  #5BA5EF;
            border: 1px solid  #5BA5EF;
        }
     .apply-text .expired {
            background-color: #2AC57D;
            color: #fff;
        }


      .renewal {
        position: fixed;
        bottom: 0px;
        width: 100%;
        height: 52px;
        background-color: #fff;
    }
    .renewal-p {
        line-height: 52px;
        color: #989898;
        font-size: 14px;
        float: right;
        margin: 0;
    }
    #renewal {
        width: 152px;
        height: 52px;
        background-color: #E64347;
        float: right;
        border: none;
        margin-left: 40px;
        color: #fff;
        font-size: 18px;
        font-weight:bold;
    }
    .renewal-p span{
        color: #E64347;
    }
</style>

<div class="apply-content">   
    <!--<div class="apply-box">
        <img src="../img/Apply1.png" />
        <div class="apply-text">
            <h5>基本应用</h5>
            <p>适用于连锁门店，启用应用后，通过系统快…</p>
            <span>¥ 236/年</span>
            <input type="button" value="立即购买" />
        </div>
    </div>-->
    @{
        System.Data.DataTable dtAppInfo = (@ViewBag.AppInfo as System.Data.DataTable);
        if (dtAppInfo != null)
        {
            foreach (System.Data.DataRow dr in dtAppInfo.Rows)
            {
                <div class="apply-box">
                    <img src="../img/@dr["FImage"].ToString()" />
                    <div class="apply-text">
                        <h5>@dr["FName"].ToString()</h5>
                        <p>@dr["FExplain"].ToString()</p>
                        <span>¥ @dr["FSalesPrice"].ToString()/年</span>
                            @{
                            if (@dr["FStateID"].ToString() == "2")
                                {
                                    <input type="button" class="overdue" value="即将到期" onclick="GoRenew()"/>
                                }
                                else if (@dr["FStateID"].ToString() == "1")
                                {
                                    <input type="button" class="expired" value="前往管理" onclick="GoRenew()"/>
                                }
                                else if (@dr["FStateID"].ToString() == "3")
                                {
                                    <input type="button" class="management" value="已过期" onclick="GoRenew()"/>
                                }
                                else if (@dr["FStateID"].ToString() == "4")
                                {
                                    <input type="button" class="management" value="前往充值" onclick="GoRecharge()"/>
                                }
                                else
                                {
                                    string AppID = dr["FItemID"].ToString();
                                        <input id='btn' type="button" value="立即启用" onclick='AppEnable(this,@AppID)'/>
                                }
                            }
                    </div>
                </div>                 
            }
        }
    <div class="renewal">       
        <input id="renewal" type="button" value="前往续费" onclick="GoRenew()"/>
        <p class="renewal-p">当前已启用<span id="AllApps">@dtAppInfo.Compute("count(FItemID)", "FStateID<>0").ToString()</span>个应用，其中已过期
            <span id="AboutApps">@dtAppInfo.Compute("count(FItemID)", "FStateID=3").ToString()</span>个，即将过期
            <span id="ExpireApps">@dtAppInfo.Compute("count(FItemID)", "FStateID=2").ToString()</span>个，正常状态
            <span id="NormalApps">@dtAppInfo.Compute("count(FItemID)", "FStateID=1").ToString()</span>个。</p>
    </div>
    }
</div>

<script>
    mini.parse();

    function AppEnable(obj,AppID) {
        if($(obj).val()!='立即启用'){
            GoRenew();
            return;
        }
        if(!confirm("确定要启用此应用？")) return;
        var jsonstr = '[{"mSystemAppID":"' + parent.window.getSystemAppID() + '",';
        jsonstr += '"AppID":' + AppID + '}]';
        $.post("AppCenter/TryCorpProdcut", { json: jsonstr }, function (data) {
            var mdata = mini.decode(data);
            if (mdata.status == 1)
            {
                if(parseInt(mdata.msg) > 10)
                    mini.alert("应用已成功启用");
                else
                    mini.alert("应用已成功启用，当前有十天试用期，要继续使用请前往续费");
                $(obj).addClass('overdue');
                $(obj).val('即将到期');
                var allapps = parseInt($("#AllApps").text())+1;
                var aboutapps = parseInt($("#ExpireApps").text())+1;
                $("#AllApps").text(allapps);
                $("#ExpireApps").text(aboutapps);
            }
            else
                mini.alert("启用失败," + mdata.msg);
        });
    }

    function GoRenew() {
        parent.window.showTabById("Terminal", "充值续费", "../AppCenter/Terminal?FSystemAppID=" + parent.window.getSystemAppID());
    }

    function GoRecharge(){
        parent.window.showTabById("RechargeSMS", "充值短信", "../System/RechargeSMS");
    }
</script>
